package com.gzbuswx.eshop.inventory.thread;

import com.gzbuswx.eshop.inventory.request.Request;
import com.gzbuswx.eshop.inventory.request.RequestQueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RequestProcessThreadPool {

    private ExecutorService threadPool = Executors.newFixedThreadPool(10);

    public RequestProcessThreadPool(){
        RequestQueue queues = RequestQueue.getInstance();
        for(int i=0;i<10;i++){
            ArrayBlockingQueue<Request> queue = new ArrayBlockingQueue<Request>(100);
            queues.addQueue(queue);
            threadPool.submit(new RequestProcessThread(queue));
        }
    }

    private static class Singleton{
        private static RequestProcessThreadPool instance;

        static{
            instance = new RequestProcessThreadPool();
        }
        public static  RequestProcessThreadPool getInstance(){
            return instance;
        }

    }

    public  static RequestProcessThreadPool getInstance(){
        return Singleton.getInstance();
    }

    public  static void  init(){
        getInstance();
    }



}
